package cn.edu.ccut.refactor;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;

public class SaturnRefactorActionProvider extends CommonActionProvider {
	private static final String EDIT_MENU_NAME = "common.new.edita"; //$NON-NLS-1$
	private RenameSaturnAction renameSaturnAction;
	private MoveSaturnAction moveSaturnAction;

	private ICommonViewerWorkbenchSite viewSite = null;

	private boolean contribute = false;

	public void init(ICommonActionExtensionSite aConfig) {
		if (aConfig.getViewSite() instanceof ICommonViewerWorkbenchSite) {
			viewSite = (ICommonViewerWorkbenchSite) aConfig.getViewSite();
			renameSaturnAction = new RenameSaturnAction(viewSite.getSite());
			moveSaturnAction = new MoveSaturnAction(viewSite.getSite());
			contribute = true;
		}
	}

	public void fillContextMenu(IMenuManager aMenu) {
		if (!contribute || getContext().getSelection().isEmpty()) {
			return;
		}
		renameSaturnAction.setIstructuredselection((IStructuredSelection) getContext().getSelection());
		moveSaturnAction.setIstructuredselection((IStructuredSelection) getContext().getSelection());
		IMenuManager submenu = new MenuManager(
				Messages.getString("SaturnRefactorActionProvider.1"), //$NON-NLS-1$
				EDIT_MENU_NAME);
//		submenu.add(openFileAction);
//		IStructuredSelection selection = (IStructuredSelection) getContext()
//				.getSelection();
//		IMenuManager submenu = aMenu.findMenuUsingPath(ICommonMenuConstants.GROUP_EDIT);
//			aMenu.insertAfter(ICommonMenuConstants.GROUP_EDIT, openFileAction);
		submenu.add(renameSaturnAction);
		submenu.add(moveSaturnAction);
		
//		submenu.insertAfter(null, openFileAction);
		submenu.add(new Separator());
//		addOpenWithMenu(aMenu);
		aMenu.insertAfter(ICommonMenuConstants.GROUP_EDIT, submenu);
	}

}
